package com.lmf.handler;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器类：拦截用户请求
public class MyInterceptor2 implements HandlerInterceptor {

    /**
     * 预处理方法
     * Object handler：表示被拦截的控制器对象
     * 特点：在方法控制器方法之前，执行
     *      用户请求首先到达这里
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("22222执行了preHandle方法");
        //拦截请求，并重定向到一个jsp页面
//        request.getRequestDispatcher("tips.jsp").forward(request,response);
//        return false;
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("22222执行了postHandle方法");
        
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("22222执行了afterCompletion方法");

    }
}
